import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path";
import monacoEditorPlugin from "vite-plugin-monaco-editor";

const resolve = (dir) => path.join(__dirname, dir);

const mode = process.env.MODE || "development";
const env = loadEnv(mode, process.cwd(), "");
// https://vite.dev/config/
export default defineConfig({
  base: env.VITE_APP_BASE_URL,
  resolve: {
    alias: {
      "@": resolve("./src")
    }
  },
  build: {
    sourcemap: true
  },
  plugins: [
    vue(),
    monacoEditorPlugin.default({}),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  optimizeDeps: {
    include: [
      `monaco-editor/esm/vs/language/json/json.worker`,
      `monaco-editor/esm/vs/language/css/css.worker`,
      `monaco-editor/esm/vs/language/html/html.worker`,
      `monaco-editor/esm/vs/editor/editor/editor.worker`
    ]
  }
});
